package com.zxw.web;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.context.annotation.Configuration;

import java.io.IOException;

/**
 * @author zxw
 * @date 2021-03-06 14:12
 */
@Configuration
public class Consumer {
    @RabbitListener(queues = "test", containerFactory = "simpleRabbitListenerContainerFactory")
    public void consumer(Message message, Channel channel) {
        try {
            channel.basicAck(message.getMessageProperties().getDeliveryTag(),true);
        } catch (Exception e) {
            try {
                channel.basicNack(message.getMessageProperties().getDeliveryTag(),true,true);
            } catch (IOException ioException) {
                ioException.printStackTrace();
            }
        }
    }
}
